package com.apexsoft.margin.account.management.api.http;

import com.apexsoft.margin.account.management.domain.common.model.AdapterResp;
import com.apexsoft.margin.account.management.domain.common.model.AdapterRespChild;
import com.apexsoft.margin.account.management.domain.search.model.*;
import com.apexsoft.margin.account.management.util.DealResp;
import com.apexsoft.margin.account.management.util.ResultUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/firstChainEnter")
public class FirstChainController {
    @PostMapping("/getFirstChainInfo")
    public ResultUtil getFirstChain(@RequestBody FirstChainSearchDomain domain) {
        ResultUtil resultUtil = new ResultUtil();
        List<FirstChainSearch> list = new ArrayList<>();
        if (domain.getG_funcid() != null) {
            for (int i = 0; i < 20; i++) {
                FirstChainSearch chainSearch = new FirstChainSearch("序号：" + i, "2", "3", "4", 5444L, "6", "7", 8, 9, 10, 11, 12, 13, 14, "15", 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, "30", "31", "32", "33");
                list.add(chainSearch);
            }
        } else {
            for (int i = 0; i < 2; i++) {
                FirstChainSearch chainSearch = new FirstChainSearch("序号：" + i, "2", "3", "4", 5444L, "6", "7", 8, 9, 10, 11, 12, 13, 14, "15", 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, "30", "31", "32", "33");
                list.add(chainSearch);
            }
        }
        DealResp deal =new DealResp();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        resultUtil.setTotal(list.size());
        return resultUtil;
    }
    @PostMapping("/add")
    public ResultUtil add(@RequestBody FirstChainSearchDomain domain) {
        List<FirstChainSearch> list = new ArrayList<>();
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        DealResp deal =new DealResp();
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        return resultUtil;
    }

    @PostMapping("/update")
    public ResultUtil update(@RequestBody FirstChainSearchDomain domain){
        List<FirstChainSearch> list = new ArrayList<>();
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        DealResp deal =new DealResp();
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        return resultUtil;
    }

    @PostMapping("/delete")
    public ResultUtil delete(@RequestBody FirstChainSearchDomain domain){
        List<FirstChainSearch> list = new ArrayList<>();
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        DealResp deal =new DealResp();
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        return resultUtil;
    }

    //     上传文件并返回文件内容（list形式）
    @PostMapping("/upload")
    public ResultUtil upload(@RequestBody MultipartFile file) {
        List<FirstChainSearch> list = new ArrayList<>();
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        DealResp deal =new DealResp();
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);



        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        return resultUtil;
    }

}
